package com.ymatou.iapi.trading.operate.testcase;

import java.math.BigDecimal;
import java.text.DecimalFormat;
import java.util.Map;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.trading.operate.parameter.MarkOrderEvaluatedReqBean;
import com.ymatou.iapi.trading.operate.parameter.PlaceOrderResp;
import com.ymatou.iapi.trading.operate.service.MarkOrderEvaluatedReqCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.annotation.TestSuite;
import com.ymt.utils.tag.P1;
import com.ymt.utils.tag.P3;
import com.ymttest.business.service.OrderCallService;
import com.ymttest.utils.constant.ECode;
/**
*订单评价
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_MarkOrderEvaluatedReq{
	private static MarkOrderEvaluatedReqBean markorderevaluatedreqBean;
	private static MarkOrderEvaluatedReqCall markorderevaluatedreqCall;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("订单评价");
	}

	@Before
	public void caseUp() {
		markorderevaluatedreqBean=new MarkOrderEvaluatedReqBean();
		markorderevaluatedreqCall=new MarkOrderEvaluatedReqCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(markorderevaluatedreqCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	
	@Test
    @Category(P1.class)
    @TestCase
    public void Tc_MarkOrderEvaluatedReq_001(){
		Logger.start(true, "确认收货后订单评价成功");
		try {
			//创建订单
			Logger.comment("准备前置数据");
			PlaceOrderResp placeOrderResp=new OrderCallService().createM2cOrder();

			int orderId = placeOrderResp.getOrderList().get(0).getOrderId();
			int sellerId =placeOrderResp.getOrderList().get(0).getSellerId();
			int userId =placeOrderResp.getUserId();         
			int tradingId = placeOrderResp.getTradingId();

			BigDecimal totalPrice =  placeOrderResp.getPayAmount();// 支付金额
	        // 支付订单
	        new OrderCallService().orderPayRequest(userId, totalPrice, tradingId);
	        // 接单
	        new OrderCallService().acceptOrder(orderId, sellerId);			
	     	// 商家发货
	     	new OrderCallService().dispatched(orderId, sellerId);
	     	//买家收货
	     	new OrderCallService().confirmReceive(userId, orderId);
	        Logger.comment("前置数据准备结束");	      
	        //参数
	        markorderevaluatedreqBean.setOrderId(orderId);
			//发送请求
	        markorderevaluatedreqCall.setData(markorderevaluatedreqBean);
	        markorderevaluatedreqCall.callService();
	        
	        Logger.verifyEquals(ECode.SUCCESS, markorderevaluatedreqCall.getCode(), "验证code");
	        
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
    @Category(P3.class)
    @TestCase
	 public void Tc_MarkOrderEvaluatedReq_002(){
		Logger.start(false, "订单Id为空，评论失败");
		try {
//			markorderevaluatedreqBean.setCancle(false);
			markorderevaluatedreqCall.callService();
			Logger.verifyEquals(ECode.FAILED400, markorderevaluatedreqCall.getCode(), "验证code");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}